package com.shiguiwu.springmybatis.app.controller;

import cn.hutool.json.JSONUtil;
import com.shiguiwu.springmybatis.app.dto.RequestUser;
import com.shiguiwu.springmybatis.app.service.HelloService;
import com.shiguiwu.springmybatis.spring.property.MailConfig;
import com.shiguiwu.springmybatis.spring.transaction.demo.ServiceTxA;
import com.shiguiwu.springmybatis.util.Book;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: test
 * @author: stone
 * @date: Created by 2020/11/15 9:25
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.app.controller
 */
@Controller
@Slf4j
public class HelloController {

    @Resource(name = "helloService")
    private HelloService helloService;

    @Autowired
    private ServiceTxA serviceTxA;

    //@Autowired
    //private MailConfig mailConfig;


    @GetMapping("/hello")
    public String hello(Map<String, Object> map, HttpServletRequest request) {
        log.error("访问hello接口》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
        request.getParameter("a");
        helloService.eat(2);
        //serviceTxA.m1();

        return "hello";
    }




    @ModelAttribute
    public void test() {

        System.out.println("modelAttribute>>>>>>>>>>>>>>>>>>>>>>");
    }


    @GetMapping("/shiguiwu")
    @ResponseBody
    public String shiguiwu() {

        return "shiguiwu ==> " ;
    }


    @GetMapping("/userInfo")
    @ResponseBody
    public Map<String,Object> queryUserInfo(@RequestParam String userId) {
        Book book = new Book();
        book.setName(userId);
        book.setAuthor("123");
        Map<String,Object> map = new HashMap<>();
        map.put("aa", 1);
        return map;
    }

    /**
     * 多个参数测试
     *
     * @param requestUser
     * @param type
     * @param name
     * @return
     */
    @PostMapping("many")
    @ResponseBody
    public String manyParams(@RequestBody RequestUser requestUser, String type, String name) {
        log.info("requestUser={} ,type={},name={}", JSONUtil.toJsonStr(requestUser), type, name);
        return "success";
    }


    @PostMapping("many2")
    @ResponseBody
    public String manyParams(@RequestParam("file") MultipartFile file) {
        log.info("requestUser={} ,type={},name={}", JSONUtil.toJsonStr(file));
        return "success";
    }






    @GetMapping("/json")
    @ResponseBody
    public Map json() {
        String jsonStr = "{\n" +
                "    \"result\":{\n" +
                "        \"msg\":\"查询成功！\",\n" +
                "        \"success\":true\n" +
                "    },\n" +
                "    \"header\":{\n" +
                "        \"env\":{\n" +
                "            \"dca_item\":\"\",\n" +
                "            \"formId\":\"DD_DD_SOLUTION_JOB_LIST\",\n" +
                "            \"dca_type\":\"\",\n" +
                "            \"groupId\":\"DD_DD_GT_APP_G_DXXT\",\n" +
                "            \"groupTypeId\":\"DD_DD_GT_APP\",\n" +
                "            \"userId\":\"liufang\",\n" +
                "            \"baseType\":\"Class\",\n" +
                "            \"functionId\":\"DD_DD_SOLUTION_JOB\",\n" +
                "            \"dca_class\":\"\",\n" +
                "            \"geneId\":\"DD\",\n" +
                "            \"sceneId\":\"DD_DD\",\n" +
                "            \"operationId\":\"GetData\",\n" +
                "            \"operationInstanceId\":\"DD_DD_SOLUTION_JOB_LIST_JOB_GetData\",\n" +
                "            \"mainClassId\":\"OC_Job\"\n" +
                "        },\n" +
                "        \"operation\":{\n" +
                "            \"groupId\":\"DD_DD_GT_APP_G_DXXT\",\n" +
                "            \"operationId\":\"GetData\",\n" +
                "            \"operationInstanceId\":\"DD_DD_SOLUTION_JOB_LIST_JOB_GetData\"\n" +
                "        }\n" +
                "    },\n" +
                "    \"body\":{\n" +
                "        \"data\":{\n" +
                "            \"classId\":\"OC_Job\",\n" +
                "            \"dataContent\":[\n" +
                "                {\n" +
                "                    \"instanceId\":\"fbee76695af34cec94d7d6b162e3cb6a\",\n" +
                "                    \"configId\":\"67402A412B6E91E4FB0F20DE30839D75\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJobStart2555\",\n" +
                "                    \"description\":\"新作业255\",\n" +
                "                    \"id\":\"31BEDCE386E2C05F5E2D425ED3701729\",\n" +
                "                    \"version\":\"20181128144540\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"APP\",\n" +
                "                        \"RELEASE\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"12de212b99d0484bb679ce702407adef\",\n" +
                "                    \"configId\":\"4C5D5838B2BAED4B067C2FC3724DE8A7\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJobStart256\",\n" +
                "                    \"description\":\"sdfsdfsdfsdf\",\n" +
                "                    \"id\":\"8C1BF9F379C7D5A98DB162616FDBDDBE\",\n" +
                "                    \"version\":\"20181128145928\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"OS\",\n" +
                "                        \"LINUX\",\n" +
                "                        \"RUNSTATUS\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"e70609c35f194a89932240b7d68a4623\",\n" +
                "                    \"configId\":\"E2F1B77C91287AD7D03D277576724EBE\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJob301\",\n" +
                "                    \"description\":\"新作业301\",\n" +
                "                    \"id\":\"AFEFC6B555126DE0F03DBD540D5E43EE\",\n" +
                "                    \"version\":\"20181204111441\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"OS\",\n" +
                "                        \"COMMON\",\n" +
                "                        \"CONFIG\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"dcaa7b1313f34b7687f2cd83fc16d430\",\n" +
                "                    \"configId\":\"EC907115A2282EF24ECFF9B5A02F6713\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJobStart259\",\n" +
                "                    \"description\":\"新作业259\",\n" +
                "                    \"id\":\"898E203F22EBC23ECA64A1B429290300\",\n" +
                "                    \"version\":\"20181128150642\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"ST\",\n" +
                "                        \"RUNSTATUS\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"defined\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"d3086d0e86364509970eaf4a6b772b57\",\n" +
                "                    \"configId\":\"ED76B314F2B9B82620908C45B0500A16\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJobStart260\",\n" +
                "                    \"description\":\"电子银行标准生成作业\",\n" +
                "                    \"id\":\"6967332BA048BFFD69316B811E0101C0\",\n" +
                "                    \"version\":\"20181128152242\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"APP\",\n" +
                "                        \"CONTROL\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"12382ca53f854763a7e5f0dd2d745311\",\n" +
                "                    \"configId\":\"TESTTESTTEST\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJobStart400\",\n" +
                "                    \"description\":\"新作业400\",\n" +
                "                    \"id\":\"TESTTESTTEST\",\n" +
                "                    \"version\":\"20181128150642\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"ST\",\n" +
                "                        \"RUNSTATUS\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"03e12a3086c5418885721fc5c402af1d\",\n" +
                "                    \"configId\":\"TESTTESTTEST\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJobStart4000\",\n" +
                "                    \"description\":\"新作业4000\",\n" +
                "                    \"id\":\"TESTTESTTEST002\",\n" +
                "                    \"version\":\"20181128150642\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"ST\",\n" +
                "                        \"RUNSTATUS\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"243e194b3f5244e0a76ed20d5958435e\",\n" +
                "                    \"configId\":\"62450246709C8EC05DAB1DE86AD9DE71\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJob0304\",\n" +
                "                    \"description\":\"新作业0304\",\n" +
                "                    \"id\":\"501B631FCA46B45F73C5EF6A2186BAA8\",\n" +
                "                    \"version\":\"2119\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"OS\",\n" +
                "                        \"LINUX\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"a51431cf185a4cf3a4e8603770cc6eb5\",\n" +
                "                    \"configId\":\"3710BCB45D5315B47BAD4225955E999C\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJob302\",\n" +
                "                    \"description\":\"新作业302\",\n" +
                "                    \"id\":\"E890BE05EDB9A575D399477EE01A8589\",\n" +
                "                    \"version\":\"20181204135231\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"DB\",\n" +
                "                        \"MYSQL\",\n" +
                "                        \"CONFIG\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"instanceId\":\"132b8dba3c864ca9b11638ba8b639514\",\n" +
                "                    \"configId\":\"B3B634071EFCF864986A0ED677F15D94\",\n" +
                "                    \"platoformDriver\":\"NSH\",\n" +
                "                    \"name\":\"newJobDBA05\",\n" +
                "                    \"description\":\"新作业DBA05\",\n" +
                "                    \"id\":\"7F9B32EBB5F9CD78ADE62A9DB3129F10\",\n" +
                "                    \"version\":\"2026095116\",\n" +
                "                    \"configItem\":[\n" +
                "                        \"OS\",\n" +
                "                        \"LINUX\"\n" +
                "                    ],\n" +
                "                    \"jobExtendType\":\"ScriptExecute\",\n" +
                "                    \"jobExtendInfo\":{\n" +
                "                        \"scriptType\":\"sh\"\n" +
                "                    },\n" +
                "                    \"status\":\"enabled\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"page\":{\n" +
                "                \"total\":9315,\n" +
                "                \"pageNumber\":1,\n" +
                "                \"pageSize\":10\n" +
                "            }\n" +
                "        },\n" +
                "        \"class\":{\n" +
                "            \"qualification\":\"\",\n" +
                "            \"classId\":\"OC_Job\",\n" +
                "            \"attributeNames\":[\n" +
                "                \"instanceId\",\n" +
                "                \"name\",\n" +
                "                \"description\",\n" +
                "                \"platoformDriver\",\n" +
                "                \"configItem\",\n" +
                "                \"jobExtendType\",\n" +
                "                \"jobExtendInfo\",\n" +
                "                \"configId\",\n" +
                "                \"version\",\n" +
                "                \"status\"\n" +
                "            ],\n" +
                "            \"relationshipClass\":[\n" +
                "\n" +
                "            ],\n" +
                "            \"page\":{\n" +
                "                \"total\":9315,\n" +
                "                \"pageNumber\":1,\n" +
                "                \"pageSize\":10\n" +
                "            },\n" +
                "            \"sort\":{\n" +
                "                \"{'name'\":\"'acs'}\"\n" +
                "            },\n" +
                "            \"operation\":[\n" +
                "\n" +
                "            ]\n" +
                "        }\n" +
                "    }\n" +
                "}";
        //JSONObject jsonObject = JSONUtil.parseObj(jsonStr);
        Map map = JSONUtil.toBean(jsonStr, Map.class);
        return map;
    }
}
